package com.nfit.shopcommon.exception;

import com.nfit.shopmodel.vo.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * ClassName:GlobalExceptionHandlers
 * Package:com.nfit.shopcommon.exception
 * Description
 *
 * * @ControllerAdvice ： Controller增强器,给controller增加统一的操作和处理
 * * @ExceptionHandler : 捕获controller抛出指定类型异常
 *
 * @Author L
 * @Create 2024/11/15 19:44
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandlers {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handleException(Exception e) {
        log.error("异常消息：", e);
        return Result.build(null,201,e.getMessage());
    }

    /**
     *自定义异常
     * @param e 自定义异常处理类
     */
    @ExceptionHandler(value = CustomException.class)
    @ResponseBody
    public Result error(CustomException e){
        log.error("自定义异常消息：", e);
        return Result.build(null,e.getResultCodeEnum());
    }

}
